<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="E3," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="流光容易把人跑，红了樱桃，绿了芭蕉。  ActiveMq安装 把ActiveMQ 的压缩包上传到Linux系统，解压。 使用bin目录下的activemq命令启动   ./activemq start 进入管理后台 http://192.168.25.168:8161/admin 账号密码都是admin">
<meta name="keywords" content="E3">
<meta property="og:type" content="article">
<meta property="og:title" content="E3-Six">
<meta property="og:url" content="http://yoursite.com/2017/06/29/E3-Six/index.html">
<meta property="og:site_name" content="JokerLiang">
<meta property="og:description" content="流光容易把人跑，红了樱桃，绿了芭蕉。  ActiveMq安装 把ActiveMQ 的压缩包上传到Linux系统，解压。 使用bin目录下的activemq命令启动   ./activemq start 进入管理后台 http://192.168.25.168:8161/admin 账号密码都是admin">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-06-29T15:07:06.513Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="E3-Six">
<meta name="twitter:description" content="流光容易把人跑，红了樱桃，绿了芭蕉。  ActiveMq安装 把ActiveMQ 的压缩包上传到Linux系统，解压。 使用bin目录下的activemq命令启动   ./activemq start 进入管理后台 http://192.168.25.168:8161/admin 账号密码都是admin">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/06/29/E3-Six/"/>





  <title> E3-Six | JokerLiang </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  








  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1260895995&web_id=1260895995" language="JavaScript"></script>
  </div>





  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">JokerLiang</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">永远年轻，永远热泪盈眶。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/06/29/E3-Six/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="JokerLiang">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/me.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="JokerLiang">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="JokerLiang" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                E3-Six
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-06-29T23:06:44+08:00">
                2017-06-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/E3/" itemprop="url" rel="index">
                    <span itemprop="name">E3</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>&#x6D41;&#x5149;&#x5BB9;&#x6613;&#x628A;&#x4EBA;&#x8DD1;&#xFF0C;&#x7EA2;&#x4E86;&#x6A31;&#x6843;&#xFF0C;&#x7EFF;&#x4E86;&#x82AD;&#x8549;&#x3002;</p>
</blockquote>
<h2 id="ActiveMq"><a href="#ActiveMq" class="headerlink" title="ActiveMq"></a>ActiveMq</h2><h3 id="&#x5B89;&#x88C5;"><a href="#&#x5B89;&#x88C5;" class="headerlink" title="&#x5B89;&#x88C5;"></a>&#x5B89;&#x88C5;</h3><ol>
<li>&#x628A;ActiveMQ &#x7684;&#x538B;&#x7F29;&#x5305;&#x4E0A;&#x4F20;&#x5230;Linux&#x7CFB;&#x7EDF;&#xFF0C;&#x89E3;&#x538B;&#x3002;</li>
<li>&#x4F7F;&#x7528;bin&#x76EE;&#x5F55;&#x4E0B;&#x7684;activemq&#x547D;&#x4EE4;&#x542F;&#x52A8;   ./activemq start</li>
<li>&#x8FDB;&#x5165;&#x7BA1;&#x7406;&#x540E;&#x53F0; <a href="http://192.168.25.168:8161/admin" target="_blank" rel="noopener">http://192.168.25.168:8161/admin</a> &#x8D26;&#x53F7;&#x5BC6;&#x7801;&#x90FD;&#x662F;admin<a id="more"></a>
<h3 id="Queue&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;"><a href="#Queue&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;" class="headerlink" title="Queue&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;"></a>Queue&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;</h3><h4 id="&#x751F;&#x4EA7;&#x8005;"><a href="#&#x751F;&#x4EA7;&#x8005;" class="headerlink" title="&#x751F;&#x4EA7;&#x8005;"></a>&#x751F;&#x4EA7;&#x8005;</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line">	<span class="comment">//&#x4F7F;&#x7528;Queue&#xFF0C;&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x6CD5;&#x53D1;&#x9001;&#x6D88;&#x606F;</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fun1</span><span class="params">()</span> <span class="keyword">throws</span> Exception</span>{</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E00;&#x6B65;&#xFF1A;&#x521B;&#x5EFA;ConnectionFactory&#x5BF9;&#x8C61;&#xFF0C;&#x9700;&#x8981;&#x6307;&#x5B9A;&#x670D;&#x52A1;&#x7AEF;ip&#x53CA;&#x7AEF;&#x53E3;&#x53F7;&#x3002;</span></span><br><span class="line">		ConnectionFactory factory = <span class="keyword">new</span> ActiveMQConnectionFactory(<span class="string">&quot;tcp://192.168.25.130:61616&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E8C;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;ConnectionFactory&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Connection&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		Connection connection = factory.createConnection();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E09;&#x6B65;&#xFF1A;&#x5F00;&#x542F;&#x8FDE;&#x63A5;&#xFF0C;&#x8C03;&#x7528;Connection&#x5BF9;&#x8C61;&#x7684;start&#x65B9;&#x6CD5;&#x3002;</span></span><br><span class="line">		connection.start();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x56DB;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Connection&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Session&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		<span class="comment">//&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x8BBE;&#x7F6E;&#x4E3A;false</span></span><br><span class="line">		Session session = connection.createSession(<span class="keyword">false</span>,Session.AUTO_ACKNOWLEDGE);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E94;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Session&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Destination&#x5BF9;&#x8C61;&#xFF08;topic&#x3001;queue&#xFF09;&#xFF0C;&#x6B64;&#x5904;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Queue&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		<span class="comment">//&#x53C2;&#x6570;&#xFF1A;&#x961F;&#x5217;&#x7684;&#x540D;&#x79F0;</span></span><br><span class="line">		Queue queue = session.createQueue(<span class="string">&quot;test-AMQueue&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x516D;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Session&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Producer&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		MessageProducer messageProducer = session.createProducer(queue);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E03;&#x6B65;&#xFF1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Message&#x5BF9;&#x8C61;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;TextMessage&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		TextMessage message = session.createTextMessage(<span class="string">&quot;&#x6D4B;&#x8BD5;&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;&#x901A;&#x8BAF;&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x516B;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Producer&#x5BF9;&#x8C61;&#x53D1;&#x9001;&#x6D88;&#x606F;&#x3002;</span></span><br><span class="line">		messageProducer.send(message);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E5D;&#x6B65;&#xFF1A;&#x5173;&#x95ED;&#x8D44;&#x6E90;(3&#x4E2A;)&#x3002;</span></span><br><span class="line">		messageProducer.close();</span><br><span class="line">		session.close();</span><br><span class="line">		connection.close();</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h4 id="&#x6D88;&#x8D39;&#x8005;"><a href="#&#x6D88;&#x8D39;&#x8005;" class="headerlink" title="&#x6D88;&#x8D39;&#x8005;"></a>&#x6D88;&#x8D39;&#x8005;</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">	<span class="meta">@Test</span>   </span><br><span class="line">	<span class="comment">//&#x4F7F;&#x7528;Queue&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;&#x63A5;&#x53D7;&#x6D88;&#x606F;		&#x6D88;&#x8D39;&#x8005;</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fun2</span><span class="params">()</span> <span class="keyword">throws</span> Exception</span>{</span><br><span class="line"><span class="comment">//		&#x6D88;&#x8D39;&#x8005;&#xFF1A;&#x63A5;&#x6536;&#x6D88;&#x606F;&#x3002;</span></span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E00;&#x6B65;&#xFF1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;ConnectionFactory&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		ConnectionFactory connectionFactory = <span class="keyword">new</span> ActiveMQConnectionFactory(<span class="string">&quot;tcp://192.168.25.130:61616&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E8C;&#x6B65;&#xFF1A;&#x4ECE;ConnectionFactory&#x5BF9;&#x8C61;&#x4E2D;&#x83B7;&#x5F97;&#x4E00;&#x4E2A;Connection&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		Connection connection = connectionFactory.createConnection();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E09;&#x6B65;&#xFF1A;&#x5F00;&#x542F;&#x8FDE;&#x63A5;&#x3002;&#x8C03;&#x7528;Connection&#x5BF9;&#x8C61;&#x7684;start&#x65B9;&#x6CD5;&#x3002;</span></span><br><span class="line">		connection.start();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x56DB;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Connection&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Session&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		Session session = connection.createSession(<span class="keyword">false</span>, Session.AUTO_ACKNOWLEDGE);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E94;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Session&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Destination&#x5BF9;&#x8C61;&#x3002;&#x548C;&#x53D1;&#x9001;&#x7AEF;&#x4FDD;&#x6301;&#x4E00;&#x81F4;queue&#xFF0C;&#x5E76;&#x4E14;&#x961F;&#x5217;&#x7684;&#x540D;&#x79F0;&#x4E00;&#x81F4;&#x3002;</span></span><br><span class="line">		Queue queue = session.createQueue(<span class="string">&quot;test-AMQueue&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x516D;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Session&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Consumer&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		MessageConsumer consumer = session.createConsumer(queue);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E03;&#x6B65;&#xFF1A;&#x63A5;&#x6536;&#x6D88;&#x606F;&#x3002;</span></span><br><span class="line">		consumer.setMessageListener(<span class="keyword">new</span> MessageListener() {</span><br><span class="line">			</span><br><span class="line">			<span class="meta">@Override</span></span><br><span class="line">			<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onMessage</span><span class="params">(Message msg)</span> </span>{</span><br><span class="line">				TextMessage textMessage  = (TextMessage) msg;</span><br><span class="line">				String string = <span class="keyword">null</span>;</span><br><span class="line">				<span class="keyword">try</span> {</span><br><span class="line"><span class="comment">//					&#x7B2C;&#x516B;&#x6B65;&#xFF1A;&#x6253;&#x5370;&#x6D88;&#x606F;&#x3002;</span></span><br><span class="line">					string = textMessage.getText();</span><br><span class="line">					System.out.println(string);</span><br><span class="line">				} <span class="keyword">catch</span> (JMSException e) {</span><br><span class="line">					e.printStackTrace();</span><br><span class="line">				}</span><br><span class="line">				</span><br><span class="line">			}</span><br><span class="line">		});</span><br><span class="line"></span><br><span class="line">		System.in.read();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E5D;&#x6B65;&#xFF1A;&#x5173;&#x95ED;&#x8D44;&#x6E90;</span></span><br><span class="line">		consumer.close();</span><br><span class="line">		session.close();</span><br><span class="line">		connection.close();</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
<h3 id="Topic&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;"><a href="#Topic&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;" class="headerlink" title="Topic&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;"></a>Topic&#x70B9;&#x5BF9;&#x70B9;&#x65B9;&#x5F0F;</h3><h4 id="&#x751F;&#x4EA7;&#x8005;-1"><a href="#&#x751F;&#x4EA7;&#x8005;-1" class="headerlink" title="&#x751F;&#x4EA7;&#x8005;"></a>&#x751F;&#x4EA7;&#x8005;</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">	<span class="meta">@Test</span></span><br><span class="line">	<span class="comment">// &#x4F7F;&#x7528;Topic&#x65B9;&#x5F0F; &#x5B9E;&#x73B0; &#x5E7F;&#x64AD;&#x65B9;&#x5F0F;&#x53D1;&#x9001;&#x6D88;&#x606F;</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fn3</span><span class="params">()</span> <span class="keyword">throws</span> Exception</span>{</span><br><span class="line"><span class="comment">//		&#x4F7F;&#x7528;&#x6B65;&#x9AA4;&#xFF1A;</span></span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E00;&#x6B65;&#xFF1A;&#x521B;&#x5EFA;ConnectionFactory&#x5BF9;&#x8C61;&#xFF0C;&#x9700;&#x8981;&#x6307;&#x5B9A;&#x670D;&#x52A1;&#x7AEF;ip&#x53CA;&#x7AEF;&#x53E3;&#x53F7;&#x3002;</span></span><br><span class="line">		ConnectionFactory connectionFactory = <span class="keyword">new</span> ActiveMQConnectionFactory(<span class="string">&quot;tcp://192.168.25.130:61616&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E8C;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;ConnectionFactory&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Connection&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		Connection connection = connectionFactory.createConnection();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E09;&#x6B65;&#xFF1A;&#x5F00;&#x542F;&#x8FDE;&#x63A5;&#xFF0C;&#x8C03;&#x7528;Connection&#x5BF9;&#x8C61;&#x7684;start&#x65B9;&#x6CD5;&#x3002;</span></span><br><span class="line">		connection.start();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x56DB;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Connection&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Session&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		Session session = connection.createSession(<span class="keyword">false</span>, Session.AUTO_ACKNOWLEDGE);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E94;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Session&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Destination&#x5BF9;&#x8C61;&#xFF08;topic&#x3001;queue&#xFF09;&#xFF0C;&#x6B64;&#x5904;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Topic&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		Topic topic = session.createTopic(<span class="string">&quot;Test-topic&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x516D;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Session&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Producer&#x5BF9;&#x8C61;</span></span><br><span class="line">		MessageProducer producer = session.createProducer(topic);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E03;&#x6B65;&#xFF1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Message&#x5BF9;&#x8C61;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;TextMessage&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		TextMessage textMessage = session.createTextMessage(<span class="string">&quot;&#x8FD9;&#x662F;&#x7528;Topic&#x53D1;&#x9001;&#x6765;&#x7684;&#x6570;&#x636E;&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x516B;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Producer&#x5BF9;&#x8C61;&#x53D1;&#x9001;&#x6D88;&#x606F;&#x3002;</span></span><br><span class="line">		producer.send(textMessage);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E5D;&#x6B65;&#xFF1A;&#x5173;&#x95ED;&#x8D44;&#x6E90;</span></span><br><span class="line">		producer.close();</span><br><span class="line">		session.close();</span><br><span class="line">		connection.close();</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
<h4 id="&#x6D88;&#x8D39;&#x8005;-1"><a href="#&#x6D88;&#x8D39;&#x8005;-1" class="headerlink" title="&#x6D88;&#x8D39;&#x8005;"></a>&#x6D88;&#x8D39;&#x8005;</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line">	<span class="comment">//&#x4F7F;&#x7528;Topic &#x63A5;&#x53D7;&#x6D88;&#x606F;</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fun4</span><span class="params">()</span> <span class="keyword">throws</span> Exception</span>{</span><br><span class="line"><span class="comment">//		&#x6D88;&#x8D39;&#x8005;&#xFF1A;&#x63A5;&#x6536;&#x6D88;&#x606F;&#x3002;</span></span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E00;&#x6B65;&#xFF1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;ConnectionFactory&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		ConnectionFactory connectionFactory = <span class="keyword">new</span> ActiveMQConnectionFactory(<span class="string">&quot;tcp://192.168.25.130:61616&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E8C;&#x6B65;&#xFF1A;&#x4ECE;ConnectionFactory&#x5BF9;&#x8C61;&#x4E2D;&#x83B7;&#x5F97;&#x4E00;&#x4E2A;Connection&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		Connection connection = connectionFactory.createConnection();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E09;&#x6B65;&#xFF1A;&#x5F00;&#x542F;&#x8FDE;&#x63A5;&#x3002;&#x8C03;&#x7528;Connection&#x5BF9;&#x8C61;&#x7684;start&#x65B9;&#x6CD5;&#x3002;</span></span><br><span class="line">		connection.start();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x56DB;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Connection&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Session&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		Session session = connection.createSession(<span class="keyword">false</span>, Session.AUTO_ACKNOWLEDGE);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E94;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Session&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Destination&#x5BF9;&#x8C61;&#x3002;&#x548C;&#x53D1;&#x9001;&#x7AEF;&#x4FDD;&#x6301;&#x4E00;&#x81F4;topic&#xFF0C;&#x5E76;&#x4E14;&#x8BDD;&#x9898;&#x7684;&#x540D;&#x79F0;&#x4E00;&#x81F4;&#x3002;</span></span><br><span class="line">		Topic topic = session.createTopic(<span class="string">&quot;Test-topic&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x516D;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;Session&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;Consumer&#x5BF9;&#x8C61;&#x3002;</span></span><br><span class="line">		MessageConsumer consumer = session.createConsumer(topic);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E03;&#x6B65;&#xFF1A;&#x63A5;&#x6536;&#x6D88;&#x606F;&#x3002;</span></span><br><span class="line">		consumer.setMessageListener(<span class="keyword">new</span> MessageListener() {</span><br><span class="line">			</span><br><span class="line">			<span class="meta">@Override</span></span><br><span class="line">			<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onMessage</span><span class="params">(Message msg)</span> </span>{</span><br><span class="line">				 TextMessage  textMessage = (TextMessage) msg;</span><br><span class="line">				 <span class="keyword">try</span> {</span><br><span class="line">					String text = textMessage.getText();</span><br><span class="line"><span class="comment">//					&#x7B2C;&#x516B;&#x6B65;&#xFF1A;&#x6253;&#x5370;&#x6D88;&#x606F;&#x3002;</span></span><br><span class="line">					System.out.println(text);</span><br><span class="line">				} <span class="keyword">catch</span> (JMSException e) {</span><br><span class="line">					e.printStackTrace();</span><br><span class="line">				}</span><br><span class="line">				</span><br><span class="line">			}</span><br><span class="line">		});</span><br><span class="line">		System.in.read();</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E5D;&#x6B65;&#xFF1A;&#x5173;&#x95ED;&#x8D44;&#x6E90;</span></span><br><span class="line">		consumer.close();</span><br><span class="line">		session.close();</span><br><span class="line">		connection.close();</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
<h3 id="ActiveMq&#x6574;&#x5408;Spring"><a href="#ActiveMq&#x6574;&#x5408;Spring" class="headerlink" title="ActiveMq&#x6574;&#x5408;Spring"></a>ActiveMq&#x6574;&#x5408;Spring</h3><ol>
<li>&#x5BFC;JAR&#x5305;<h4 id="&#x53D1;&#x9001;&#x7AEF;&#x914D;&#x7F6E;&#x6587;&#x4EF6;"><a href="#&#x53D1;&#x9001;&#x7AEF;&#x914D;&#x7F6E;&#x6587;&#x4EF6;" class="headerlink" title="&#x53D1;&#x9001;&#x7AEF;&#x914D;&#x7F6E;&#x6587;&#x4EF6;"></a>&#x53D1;&#x9001;&#x7AEF;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">beans</span> <span class="attr">xmlns</span>=<span class="string">&quot;http://www.springframework.org/schema/beans&quot;</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xmlns:context</span>=<span class="string">&quot;http://www.springframework.org/schema/context&quot;</span> <span class="attr">xmlns:p</span>=<span class="string">&quot;http://www.springframework.org/schema/p&quot;</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xmlns:aop</span>=<span class="string">&quot;http://www.springframework.org/schema/aop&quot;</span> <span class="attr">xmlns:tx</span>=<span class="string">&quot;http://www.springframework.org/schema/tx&quot;</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xmlns:xsi</span>=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xsi:schemaLocation</span>=<span class="string">&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">&lt;!-- &#x771F;&#x6B63;&#x53EF;&#x4EE5;&#x4EA7;&#x751F;Connection&#x7684;ConnectionFactory&#xFF0C;&#x7531;&#x5BF9;&#x5E94;&#x7684; JMS&#x670D;&#x52A1;&#x5382;&#x5546;&#x63D0;&#x4F9B; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;targetConnectionFactory&quot;</span> <span class="attr">class</span>=<span class="string">&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;brokerURL&quot;</span> <span class="attr">value</span>=<span class="string">&quot;tcp://192.168.25.168:61616&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- Spring&#x7528;&#x4E8E;&#x7BA1;&#x7406;&#x771F;&#x6B63;&#x7684;ConnectionFactory&#x7684;ConnectionFactory --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;connectionFactory&quot;</span></span></span><br><span class="line"><span class="tag">		<span class="attr">class</span>=<span class="string">&quot;org.springframework.jms.connection.SingleConnectionFactory&quot;</span>&gt;</span></span><br><span class="line">		<span class="comment">&lt;!-- &#x76EE;&#x6807;ConnectionFactory&#x5BF9;&#x5E94;&#x771F;&#x5B9E;&#x7684;&#x53EF;&#x4EE5;&#x4EA7;&#x751F;JMS Connection&#x7684;ConnectionFactory --&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;targetConnectionFactory&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;targetConnectionFactory&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- &#x914D;&#x7F6E;&#x751F;&#x4EA7;&#x8005; --&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- Spring&#x63D0;&#x4F9B;&#x7684;JMS&#x5DE5;&#x5177;&#x7C7B;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x6D88;&#x606F;&#x53D1;&#x9001;&#x3001;&#x63A5;&#x6536;&#x7B49; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;jmsTemplate&quot;</span> <span class="attr">class</span>=<span class="string">&quot;org.springframework.jms.core.JmsTemplate&quot;</span>&gt;</span></span><br><span class="line">		<span class="comment">&lt;!-- &#x8FD9;&#x4E2A;connectionFactory&#x5BF9;&#x5E94;&#x7684;&#x662F;&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x7684;Spring&#x63D0;&#x4F9B;&#x7684;&#x90A3;&#x4E2A;ConnectionFactory&#x5BF9;&#x8C61; --&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;connectionFactory&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;connectionFactory&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!--&#x8FD9;&#x4E2A;&#x662F;&#x961F;&#x5217;&#x76EE;&#x7684;&#x5730;&#xFF0C;&#x70B9;&#x5BF9;&#x70B9;&#x7684; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;queueDestination&quot;</span> <span class="attr">class</span>=<span class="string">&quot;org.apache.activemq.command.ActiveMQQueue&quot;</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">value</span>&gt;</span>spring-queue<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!--&#x8FD9;&#x4E2A;&#x662F;&#x4E3B;&#x9898;&#x76EE;&#x7684;&#x5730;&#xFF0C;&#x4E00;&#x5BF9;&#x591A;&#x7684; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;topicDestination&quot;</span> <span class="attr">class</span>=<span class="string">&quot;org.apache.activemq.command.ActiveMQTopic&quot;</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">value</span>=<span class="string">&quot;topic&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
</ol>
<h4 id="&#x53D1;&#x9001;&#x7AEF;&#x4EE3;&#x7801;&#x5199;&#x6CD5;"><a href="#&#x53D1;&#x9001;&#x7AEF;&#x4EE3;&#x7801;&#x5199;&#x6CD5;" class="headerlink" title="&#x53D1;&#x9001;&#x7AEF;&#x4EE3;&#x7801;&#x5199;&#x6CD5;"></a>&#x53D1;&#x9001;&#x7AEF;&#x4EE3;&#x7801;&#x5199;&#x6CD5;</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testSpringActiveMq</span><span class="params">()</span> <span class="keyword">throws</span> Exception </span>{</span><br><span class="line">	<span class="comment">//&#x521D;&#x59CB;&#x5316;spring&#x5BB9;&#x5668;</span></span><br><span class="line">	ApplicationContext applicationContext = <span class="keyword">new</span> ClassPathXmlApplicationContext(<span class="string">&quot;classpath:spring/applicationContext-activemq.xml&quot;</span>);</span><br><span class="line">	<span class="comment">//&#x4ECE;spring&#x5BB9;&#x5668;&#x4E2D;&#x83B7;&#x5F97;JmsTemplate&#x5BF9;&#x8C61;</span></span><br><span class="line">	JmsTemplate jmsTemplate = applicationContext.getBean(JmsTemplate.class);</span><br><span class="line">	<span class="comment">//&#x4ECE;spring&#x5BB9;&#x5668;&#x4E2D;&#x53D6;Destination&#x5BF9;&#x8C61;</span></span><br><span class="line">	Destination destination = (Destination) applicationContext.getBean(<span class="string">&quot;queueDestination&quot;</span>);</span><br><span class="line">	<span class="comment">//&#x4F7F;&#x7528;JmsTemplate&#x5BF9;&#x8C61;&#x53D1;&#x9001;&#x6D88;&#x606F;&#x3002;</span></span><br><span class="line">	jmsTemplate.send(destination, <span class="keyword">new</span> MessageCreator() {</span><br><span class="line">		</span><br><span class="line">		<span class="meta">@Override</span></span><br><span class="line">		<span class="function"><span class="keyword">public</span> Message <span class="title">createMessage</span><span class="params">(Session session)</span> <span class="keyword">throws</span> JMSException </span>{</span><br><span class="line">			<span class="comment">//&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6D88;&#x606F;&#x5BF9;&#x8C61;&#x5E76;&#x8FD4;&#x56DE;</span></span><br><span class="line">			TextMessage textMessage = session.createTextMessage(<span class="string">&quot;spring activemq queue message&quot;</span>);</span><br><span class="line">			<span class="keyword">return</span> textMessage;</span><br><span class="line">		}</span><br><span class="line">	});</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="&#x63A5;&#x6536;&#x7AEF;&#x914D;&#x7F6E;&#x6587;&#x4EF6;"><a href="#&#x63A5;&#x6536;&#x7AEF;&#x914D;&#x7F6E;&#x6587;&#x4EF6;" class="headerlink" title="&#x63A5;&#x6536;&#x7AEF;&#x914D;&#x7F6E;&#x6587;&#x4EF6;"></a>&#x63A5;&#x6536;&#x7AEF;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">beans</span> <span class="attr">xmlns</span>=<span class="string">&quot;http://www.springframework.org/schema/beans&quot;</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xmlns:context</span>=<span class="string">&quot;http://www.springframework.org/schema/context&quot;</span> <span class="attr">xmlns:p</span>=<span class="string">&quot;http://www.springframework.org/schema/p&quot;</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xmlns:aop</span>=<span class="string">&quot;http://www.springframework.org/schema/aop&quot;</span> <span class="attr">xmlns:tx</span>=<span class="string">&quot;http://www.springframework.org/schema/tx&quot;</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xmlns:xsi</span>=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span></span><br><span class="line"><span class="tag">	<span class="attr">xsi:schemaLocation</span>=<span class="string">&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">&lt;!-- &#x771F;&#x6B63;&#x53EF;&#x4EE5;&#x4EA7;&#x751F;Connection&#x7684;ConnectionFactory&#xFF0C;&#x7531;&#x5BF9;&#x5E94;&#x7684; JMS&#x670D;&#x52A1;&#x5382;&#x5546;&#x63D0;&#x4F9B; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;targetConnectionFactory&quot;</span> <span class="attr">class</span>=<span class="string">&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;brokerURL&quot;</span> <span class="attr">value</span>=<span class="string">&quot;tcp://192.168.25.168:61616&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- Spring&#x7528;&#x4E8E;&#x7BA1;&#x7406;&#x771F;&#x6B63;&#x7684;ConnectionFactory&#x7684;ConnectionFactory --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;connectionFactory&quot;</span></span></span><br><span class="line"><span class="tag">		<span class="attr">class</span>=<span class="string">&quot;org.springframework.jms.connection.SingleConnectionFactory&quot;</span>&gt;</span></span><br><span class="line">		<span class="comment">&lt;!-- &#x76EE;&#x6807;ConnectionFactory&#x5BF9;&#x5E94;&#x771F;&#x5B9E;&#x7684;&#x53EF;&#x4EE5;&#x4EA7;&#x751F;JMS Connection&#x7684;ConnectionFactory --&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;targetConnectionFactory&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;targetConnectionFactory&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!--&#x8FD9;&#x4E2A;&#x662F;&#x961F;&#x5217;&#x76EE;&#x7684;&#x5730;&#xFF0C;&#x70B9;&#x5BF9;&#x70B9;&#x7684; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;queueDestination&quot;</span> <span class="attr">class</span>=<span class="string">&quot;org.apache.activemq.command.ActiveMQQueue&quot;</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">value</span>&gt;</span>spring-queue<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!--&#x8FD9;&#x4E2A;&#x662F;&#x4E3B;&#x9898;&#x76EE;&#x7684;&#x5730;&#xFF0C;&#x4E00;&#x5BF9;&#x591A;&#x7684; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;topicDestination&quot;</span> <span class="attr">class</span>=<span class="string">&quot;org.apache.activemq.command.ActiveMQTopic&quot;</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">value</span>=<span class="string">&quot;topic&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- &#x63A5;&#x6536;&#x6D88;&#x606F; --&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- &#x914D;&#x7F6E;&#x76D1;&#x542C;&#x5668; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;myMessageListener&quot;</span> <span class="attr">class</span>=<span class="string">&quot;cn.e3mall.search.listener.MyMessageListener&quot;</span> /&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- &#x6D88;&#x606F;&#x76D1;&#x542C;&#x5BB9;&#x5668; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">&quot;org.springframework.jms.listener.DefaultMessageListenerContainer&quot;</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;connectionFactory&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;connectionFactory&quot;</span> /&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;destination&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;queueDestination&quot;</span> /&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;messageListener&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;myMessageListener&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="&#x63A5;&#x6536;&#x7AEF;&#x4EE3;&#x7801;&#x5199;&#x6CD5;"><a href="#&#x63A5;&#x6536;&#x7AEF;&#x4EE3;&#x7801;&#x5199;&#x6CD5;" class="headerlink" title="&#x63A5;&#x6536;&#x7AEF;&#x4EE3;&#x7801;&#x5199;&#x6CD5;"></a>&#x63A5;&#x6536;&#x7AEF;&#x4EE3;&#x7801;&#x5199;&#x6CD5;</h4><ol>
<li>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x76D1;&#x542C;&#x5668;&#x5B9E;&#x73B0;MessageListener&#x63A5;&#x53E3;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x4E0A;&#x9762;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x8981;&#x914D;&#x7F6E;&#x3002;</li>
<li>&#x6536;&#x5230;&#x6D88;&#x606F;&#x540E; &#xFF0C; &#x4F1A;&#x56DE;&#x6389;&#x76D1;&#x542C;&#x5668;&#x3002;</li>
</ol>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/E3/" rel="tag"># E3</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/06/29/E3-Five/" rel="next" title="E3-Five">
                <i class="fa fa-chevron-left"></i> E3-Five
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/07/27/数据库基础-基于oracle/" rel="prev" title="数据库基础-基于oracle">
                数据库基础-基于oracle <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/me.jpg"
               alt="JokerLiang" />
          <p class="site-author-name" itemprop="name">JokerLiang</p>
          <p class="site-description motion-element" itemprop="description">永远年轻，永远热泪盈眶。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">61</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/LoverJoker" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/lover-easy-7/activities" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/2292572142/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.knight.ac.cn/" title="Knight" target="_blank">Knight</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://lzllzl.cn/" title="Zayvion" target="_blank">Zayvion</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://chen97.com/" title="Chens" target="_blank">Chens</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#ActiveMq"><span class="nav-number">1.</span> <span class="nav-text">ActiveMq</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装"><span class="nav-number">1.1.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Queue点对点方式"><span class="nav-number">1.2.</span> <span class="nav-text">Queue点对点方式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#生产者"><span class="nav-number">1.2.1.</span> <span class="nav-text">生产者</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#消费者"><span class="nav-number">1.2.2.</span> <span class="nav-text">消费者</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Topic点对点方式"><span class="nav-number">1.3.</span> <span class="nav-text">Topic点对点方式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#生产者-1"><span class="nav-number">1.3.1.</span> <span class="nav-text">生产者</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#消费者-1"><span class="nav-number">1.3.2.</span> <span class="nav-text">消费者</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ActiveMq整合Spring"><span class="nav-number">1.4.</span> <span class="nav-text">ActiveMq整合Spring</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#发送端配置文件"><span class="nav-number">1.4.1.</span> <span class="nav-text">发送端配置文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#发送端代码写法"><span class="nav-number">1.4.2.</span> <span class="nav-text">发送端代码写法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#接收端配置文件"><span class="nav-number">1.4.3.</span> <span class="nav-text">接收端配置文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#接收端代码写法"><span class="nav-number">1.4.4.</span> <span class="nav-text">接收端代码写法</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">JokerLiang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	




  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

  


</body>
</html>
